[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
strings Character Strings [TP]
Standard Pascal does not define a standard string data type. It does,
however, recognize string literals, such as in the statement:
Writeln('Hello, world!');
A string literal is a sequence of characters between single quotes.
One character between single quotes is considered (by Standard Pascal)
to be a character literal.
Standard Pascal allows the assignment of string literals to variables
which are declared as being PACKED ARRAY[1..N] OF Char, where N is
some constant value. However, the strings assigned to those variables
must be exactly N characters long. There is no such thing as a string
of length 0.
Turbo Pascal predefines a standard STRING data type which allows
greater flexibility than does Standard Pascal. String variables are
declared as follows:
var
Name : string[MaxLen];
where MaxLen is some constant value specifying the maximum length of
any string assigned to Name. MaxLen must be in the range 1..255. You
can then assign strings of any length from 0 up to and including
MaxLen. A string literal is any number of characters between single
quotes; the null string (length=0) is simply two single quotes with no
characters between them.
Strings are represented in Turbo Pascal as arrays of Char. A variable
declared as being STRING[MaxLen] is really ARRAY[0..MaxLen] OF Char,
with one byte per character. Location 0 is used to store the current
(as opposed to the maximum) length of the string. You can directly
reference any character in the string by subscripting as you would an
array. For example, if you assign 'Norton' to Name, then Name[4] =
't'.
Turbo Pascal defines a set of procedures and functions for string
manipulation. It also uses '+' as a concatenation operator and allows
the use of all the relational operators.
-------------------------------- Example ---------------------------------
var
Iota : string[2];
Able : string[60];
Fred : string[255];
begin
Iota := 'Hi';
Able := 'Hello, there.';
Fred := 'Well, aren''t you going to do anything?';
end.
See Also:
Char
arrays
string
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson